package com.tony.study.designMode.DM1_工厂方法;


/**
 * Created with IntelliJ IDEA.
 *
 * @Title: FactoryAllTest
 * @Auther: 皮蛋布丁
 * @Date: 2021/11/30/14:20
 * @Description:
 */
public class FactoryAllTest {
    public static void main(String[] args) {
        ChatFactory01 chatFactory1 = new ChatFactory01();
        String num = "1";
        Chat wechat1 = chatFactory1.createChat("WeChat");
        wechat1.chatting(num);
        Chat qq1 = chatFactory1.createChat("QQ");
        qq1.chatting(num);
        System.out.println("========================");
        num = "2";
        ChatFactory02 chatFactory02 = new ChatFactory02();
        Chat wechat2 = chatFactory02.createWeChat();
        wechat2.chatting(num);
        Chat qq2 = chatFactory02.createQQChat();
        qq2.chatting(num);
        System.out.println("========================");
        num = "3";
        Chat wechat3 = ChatFactory03.createWechat();
        wechat3.chatting(num);
        Chat qq3 = ChatFactory03.createQQchat();
        qq3.chatting(num);

    }
}
interface Chat {
    void chatting(String num);
}
class  WeChat implements Chat {
    @Override
    public void chatting(String num) {
        System.out.println("使用微信进行聊天"+num);
    }
}
class QQ implements Chat {
    @Override
    public void chatting(String num) {
        System.out.println("使用QQ进行聊天"+num);
    }
}
class ChatFactory01 {
    public Chat createChat(String tools) {
        if ("QQ".equals(tools)) {
            return new QQ();
        } else if ("WeChat".equals(tools)) {
            return new WeChat();
        } else {
            return null;
        }
    }
}
class ChatFactory02 {
    public Chat createQQChat(){return new QQ();}
    public Chat createWeChat(){return new WeChat();}
}
class ChatFactory03 {
    public static Chat createQQchat(){return new QQ();}
    public static Chat createWechat(){return new WeChat();}
}
